package net.hn.hnms.biz.support.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.*;
import net.hn.hnms.biz.api.feign.model.DataStateVo;
import net.hn.hnms.biz.support.domain.PressureJudgementPo;
import net.hn.hnms.biz.support.domain.SensorAlarmConfigPo;
import net.hn.hnms.biz.support.domain.SupportdataNowPo;
import net.hn.hnms.biz.support.domain.vo.MonitorEchartVo;
import net.hn.hnms.biz.support.domain.vo.StatisticalInformationCJDYVo;
import net.hn.hnms.biz.support.domain.vo.StatisticalInformationStringMapVo;
import net.hn.hnms.biz.support.mapper.PressureJudgementMapper;
import net.hn.hnms.biz.support.service.RoofService;
import net.hn.hnms.biz.support.service.RoofSupprotService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2022/11/17 15:22
 * 1.0 version
 */
@Api(value = "冲击地压", tags = {"冲击地压"})
@RestController
@RequestMapping("cjdy")
public class CjdyController {
    @Autowired
    private PressureJudgementMapper pressureJudgementMapper;

    //cjdy
    @Resource
    private RoofService roofService;
    /**
     * 顶板监测服务
     */

    @Resource
    private RoofSupprotService roofSupprotService;
    @ApiOperation("统计信息")
    @GetMapping("score")
    public R<PressureJudgementPo> score() {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.last(" limit 1");
        wrapper.orderByDesc("data_date");
        PressureJudgementPo pressureJudgementPo = pressureJudgementMapper.selectOne(wrapper);
        return R.ok(pressureJudgementPo);
    }

    @ApiOperation("cjdy统计信息-支架")
    @GetMapping("cjdyStatisticalInformation")
    public R<List<StatisticalInformationStringMapVo>> cjdyStatisticalInformation(@ApiParam(value = "煤矿编码") String mineCode) {
        StatisticalInformationCJDYVo statisticalInformationCJDYVo= roofService.cjdyStatisticalInformation(mineCode);
        List<StatisticalInformationStringMapVo> list = new ArrayList<>();
        StatisticalInformationStringMapVo maxHolderResistanceVo = new StatisticalInformationStringMapVo();
        maxHolderResistanceVo.setLable("最大支架阻力");
        maxHolderResistanceVo.setValue(statisticalInformationCJDYVo.getMaxHolderResistance().toString());
        maxHolderResistanceVo.setUnint("MPa");
        list.add(maxHolderResistanceVo);
        StatisticalInformationStringMapVo maxHolderLocationVo = new StatisticalInformationStringMapVo();
        maxHolderLocationVo.setLable("最大阻力位置");
        maxHolderLocationVo.setValue(statisticalInformationCJDYVo.getMaxHolderLocation());
        maxHolderLocationVo.setUnint("");
        list.add(maxHolderLocationVo);
        StatisticalInformationStringMapVo onLinePoint = new StatisticalInformationStringMapVo();
        onLinePoint.setLable("在线测点数");
        onLinePoint.setValue(statisticalInformationCJDYVo.getOnLinePoint().toString());
        onLinePoint.setUnint("个");
        list.add(onLinePoint);
        StatisticalInformationStringMapVo policePointVo = new StatisticalInformationStringMapVo();
        policePointVo.setLable("报警测点数");
        policePointVo.setValue(statisticalInformationCJDYVo.getPolicePoint().toString());
        policePointVo.setUnint("个");
        list.add(policePointVo);

        return R.ok(list);
    }
    @ApiOperation("支架监测")
    @GetMapping("/monitor")
    @AutoSetMineCode
    public R<MonitorEchartVo> MonitorEchart(@Param("mineCode") String mineCode) {
        MonitorEchartVo monitorEchartVo=roofSupprotService.monitorEchart(mineCode);
        return R.ok(monitorEchartVo);
    }
    @ApiOperation("支架实时")
    @GetMapping("/now")
    @AutoSetMineCode
    public R<List<SupportdataNowPo>> SupportNow(@Param("mineCode") String mineCode) {
        List<SupportdataNowPo> supportdataNowPos=roofSupprotService.selectListSuportNow(mineCode);
        return R.ok(supportdataNowPos);
    }
    @GetMapping("getZjzlMaxTime")
    @ApiOperation("支架阻力数据最新时间")
    public R<List<DataStateVo>> getZjzlMaxTime(String mineCode, String companyCode){
        return R.ok(roofService.getZjzlMaxTime( mineCode,companyCode));
    }
    @GetMapping("getDblcMaxTime")
    @ApiOperation("顶板离层数据最新时间")
    public R<List<DataStateVo>> getDblcMaxTime(String mineCode, String companyCode){
        return R.ok(roofService.getDblcMaxTime( mineCode,companyCode));
    }
    @GetMapping("getMgylMaxTime")
    @ApiOperation("锚杆锁数据最新时间")
    public R<List<DataStateVo>> getMgylMaxTime(String mineCode, String companyCode){
        return R.ok(roofService.getMgylMaxTime( mineCode,companyCode));
    }
    @GetMapping("exceedsThresholdByType/{type}")
    @ApiOperation("根据类型获取设备超限阈值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "设备类型", required = true, paramType = "query", dataType = "String")
    })
    public R<SensorAlarmConfigPo> exceedsThresholdByType(@PathVariable String type, @ApiParam(value = "煤矿编码")String mineCode){
        SensorAlarmConfigPo sensorAlarmConfigPo = roofService.exceedsThresholdByType(type, mineCode);
        return R.ok(sensorAlarmConfigPo);
    }
}
